package com.gitee.huanminabc.jlambda_sql.jdbc;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: huanmin
 * @create: 2025-04-10 12:23
 **/
public class JdbcDataSource {

    protected final static Map<String, DataSource> dataSourceMap = new HashMap<>();
    //获取
    public static DataSource getDataSource(String dbKey) {
        DataSource dataSource = dataSourceMap.get(dbKey);
        if (dataSource == null) {
            throw new RuntimeException("No data source found for key: " + dbKey);
        }
        return dataSource;
    }
    //添加数据源
    public static void addDataSource(String dbKey, DataSource dataSource) {
        dataSourceMap.put(dbKey, dataSource);
    }

    //重置dataSourceMap
    public static void resetDataSourceMap( Map<String, DataSource> newDataSourceMap) {
        dataSourceMap.clear();
        dataSourceMap.putAll(newDataSourceMap);
    }
}
